import 'package:flutter/material.dart';
import 'package:flutter_vant/main.dart';
import 'package:simulator/components/DemoView/index.dart';

class IDemoChildren {
  final String title;
  final Function()? onClick;
  const IDemoChildren({this.title = '', this.onClick});
}

class IDemoData {
  final String title;
  final bool? isCell;
  final List<IDemoChildren> children;
  final List<Widget> widgets;
  const IDemoData(
      {this.title = '',
      this.children = const [],
      this.isCell = true,
      this.widgets = const []});
}

class DemoViewGroup extends HookWidget {
  final List<IDemoData> data;
  const DemoViewGroup({Key? key, this.data = const []}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    renderCell(IDemoData item) {
      return VanCellGroup(
          children: item.children.map((el) {
        return VanCell(
          title: el.title,
          isLink: true,
          onClick: el.onClick,
        );
      }).toList());
    }

    renderView(IDemoData item) {
      return Frame(
        styles: const {CssRule.flexDirection: 'col'},
        children: item.widgets,
      );
    }

    renderList() {
      return data.map((e) {
        return DemoView(title: e.title, isGrid: false, children: [
          e.isCell == true ? renderCell(e) : renderView(e),
        ]);
      }).toList();
    }

    getStyles() {
      return {
        'main': {CssRule.padding: 10, CssRule.overflowY: 'scroll'}
      };
    }

    return Frame(styles: getStyles()['main'], children: renderList());
  }
}
